package com.test.intercepter;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AuthorityIntercepter extends AbstractInterceptor
{

	@Override
	public String intercept(ActionInvocation invocation) throws Exception
	{
		
		ActionContext ctx = invocation.getInvocationContext();
		
		Map param = ctx.getParameters();
		
		
	    String username = ((String[])ctx.getParameters().get("username"))[0];
		
		//String username = ctx.getSession().get("username").toString();
		
		System.out.println("AuthorityIntercepter: " + username);
		
		if(username.equals("zhangzm"))
		{
			ctx.put("tip", "user zhangzm is not allowed.");
			
			return Action.ERROR;
		}
		else 
		{
			return invocation.invoke();
		}
	}

}
